<template>
  <div class="contioner">
    <div ref="myChart" :style="{ width: '100%', height: '100%' }"></div>
  </div>
</template>
      
  <script lang="ts" setup>
import * as echarts from 'echarts'
import { Message } from '@arco-design/web-vue'
import { ref, reactive, onMounted, watch } from 'vue'
//引入封装post
import { post } from '@/api/http'
import dayjs from 'dayjs'
//getlist初始化接口参数
let query: any = reactive({
  beginDate: dayjs().format('YYYY-MM-DD'), //当天日期
    planOrderCode: '',
})

const option = ref({
  title: {
    text: '双面机运行效率',
  },
  tooltip: {
    trigger: 'axis',
  },
  // legend: {
  //   data: ['当日', '当月'],
  // },
  grid: {
    left: '3%',
    right: '4%',
    bottom: '3%',
    containLabel: true,
  },
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    axisLabel: {
      inside: false,
      textStyle: {
        fontSize: '12',
      },
      padding: [5, 0, 0, -5], //文字左右定位
    },
  },
  yAxis: {
    type: 'value',
    min: 0,
    max: 100,
    splitNumber: 10,
    axisLabel: {
      formatter: '{value} %',
    },
  },
  series: [
    {
      name: '当日',
      type: 'line',
      data: [],
      label: { show: true, position: 'top', distance: 10, formatter: '{c}%', fontSize: 12 },
    },
    {
      name: '当月',
      type: 'line',
      data: [],
      label: { show: true, position: 'top', distance: 10, formatter: '{c}%', fontSize: 12 },
    },
  ],
})
let state: any = null
//初始化
onMounted(async () => {
  selectJt()
    // state = states()
  // state.setOption(option.value)
})
const myChart: any = ref()
const states = () => {
  return echarts.init(myChart.value)
}
function selectJt() {
  post({
    url: 'qms/report/machineEfficiencyReport',
    data: {
      "firmId": query.planOrderCode, //公司ID
      "machineTypeName": "双面机", //机台类型
      "machineCode": "", //设备编号机器编号
      "date": query.beginDate //日期时间
    }
  }).then((res: any) => {
    if (res.code == 200) {
      option.value.xAxis.data = res.data.map((o: any) => o.machine)
      option.value.series[0].data = res.data.map((o: any) => o.dayBigDecimal)
      option.value.series[1].data = res.data.map((o: any) => o.mouthBigDecimal)
      state = states()
      state.setOption(option.value)
    } else {
      Message.error(res.message)
    }
  })
}
window.addEventListener('resize', updateChartSize)
function updateChartSize() {
  state.resize()
}
</script>
  <script lang="ts">
export default defineComponent({
  name: 'DoubleSidedMachine',
})
</script>
  <style scoped>
.contioner {
  width: 100%;
  height: 100%;
  background: #fff;
  padding: 10px;
}

:deep(.ag-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
  user-select: initial;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-user-select: text;
}
</style>
      